Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@janiscommerce/model-controller
Advanced tools
The `model-controller` module allows you to get a controller/model class or instance easily
The model-controller
module allows you to get a controller/model class or instance easily.
The module will search recursively the files in your root path inside the folders controllers/**
and models/**
.
npm install @janiscommerce/model-controller
The client injection is useful when you have a dedicated database per client.
Using the public setter client
, the client will be stored in the controller
instance.
All the controllers and models getted using that controller will have the client injected.
The Model
uses Database Dispatcher for getting the correct DBDriver for a Model
.
If you have the connection settings you should add a databaseKey
getter in you Model
.
class MyModel extends Model {
get databaseKey() {
return 'core';
}
}
Database Dispatcher will try to use one of the following settings
/path/to/root/.janiscommercerc.json
:{
"database": {
"core": {
"host": "http://my-host-name.org",
"type": "mysql",
// ...
}
}
}
DB_CORE_HOST = "http://my-host-name.org";
DB_CORE_DATABASE = "db-name";
DB_CORE_USER = "user";
DB_CORE_PASSWORD = "foo123456";
When your Model
is a Client Model, and the database connection settings are in the client injected, you don't need to configurate the databaseKey
.
You can add settings for the fields in the connection, the fields are the following.
For settings the package use Settings.
Field | Default value | Description |
---|---|---|
clients.fields.read.host | dbReadHost | The host for DB Read |
clients.fields.read.database | dbReadDatabase | The database name for DB Read |
clients.fields.read.user | dbReadUser | The database username for DB Read |
clients.fields.read.password | dbReadPassword | The database password for DB Read |
clients.fields.read.port | dbReadPort | The database port for DB Read |
clients.fields.write.host | dbWriteHost | The host for DB Write |
clients.fields.write.database | dbWriteDatabase | The database name for DB Write |
clients.fields.write.user | dbWriteUser | The database username for DB Write |
clients.fields.write.password | dbWritePassword | The database password for DB Write |
clients.fields.write.port | dbWritePort | The database port for DB Write |
Example of settings:
// .janiscommercerc.json
{
"clients": {
"fields": {
"read": {
"host": "dbReadHost",
"database": "dbReadDatabase",
"user": "dbReadUser",
"password": "dbReadPassword",
"port": "dbReadPort"
},
"write": {
"host": "dbWriteHost",
"database": "dbWriteDatabase",
"user": "dbWriteUser",
"password": "dbWritePassword",
"port": "dbWritePort"
}
}
}
}
Product
classconst { Controller } = require('@janiscommerce/model-controller');
// To get the Product class from e.g. 'path/to/root/controllers/product.js'
const ProductController = Controller.get('product'); // this returns the product class
Product
instanceconst { Controller } = require('@janiscommerce/model-controller');
// To get the Product instance from e.g. 'path/to/root/controllers/product.js'
const productController = Controller.getInstance('product');
Product
model instance from a Product
instanceconst { Controller } = require('@janiscommerce/model-controller');
// To get the Product instance from e.g. 'path/to/root/controllers/product.js'
const productController = Controller.getInstance('product');
// To get the Product Model class from e.g. 'path/to/root/models/product.js'
const myProduct = productController.getModel();
Product
modelconst { Model } = require('@janiscommerce/model-controller');
// To get the Product Model class from e.g. 'path/to/root/models/product.js'
const ProductModel = Model.get('product');
Product
model instanceconst { Model } = require('@janiscommerce/model-controller');
// To get the Product Model class from e.g. 'path/to/root/models/product.js'
const productModel = Model.getInstance('product');
const { Controller } = require('@janiscommerce/model-controller');
const productController = Controller.getInstance('product');
productController.client = {
id: 1,
name: 'my-client-name',
foo: 'bar'
};
const products = await productController.get(); // get from DB using model + database-dispatcher. see @janiscommerce/database-dispatcher
const categoryController = productController.getController('category');
console.log(categoryController.client);
/** -- Expected output:
{
id: 1,
name: 'my-client-name',
foo: 'bar'
}
*/
const categories = await categoryController.get(); // get from DB, should be the same DB than productsController
FAQs
The `model-controller` module allows you to get a controller/model class or instance easily
The npm package @janiscommerce/model-controller receives a total of 2 weekly downloads. As such, @janiscommerce/model-controller popularity was classified as not popular.
We found that @janiscommerce/model-controller demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.